<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="资源文件名称" prop="fileName">
        <el-input
          v-model="queryParams.fileName"
          placeholder="请输入资源文件名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="文件编号" prop="taskNo">
        <el-input
          v-model="queryParams.taskNo"
          placeholder="请输入文件编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="上传科室" prop="department">
        <el-input
          v-model="queryParams.department"
          placeholder="请输入上传科室"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="录入时间">
          <el-date-picker
            v-model="queryParams.dateRange"
            style="width: 220px"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
      </el-form-item>
      <el-form-item label="文件类型" prop="fileType">
         <el-input
          v-model="queryParams.fileType"
          placeholder="请输入文件类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
        <!-- <el-select v-model="queryParams.fileType" placeholder="请选择文件类型" clearable>
          <el-option label="文件" :value="1"></el-option>
          <el-option label="文件夹" :value="2"></el-option>
        </el-select> -->
      </el-form-item>
      <el-form-item label="上传人" prop="updateBy">
        <el-input
          v-model="queryParams.updateBy"
          placeholder="请输入上传人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleBack"
        >返回</el-button>
      </el-col>

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="postList" @selection-change="handleSelectionChange">
      <el-table-column label="文件id" align="center" prop="id" />
      <el-table-column label="文件夹名" align="center" prop="fileName" />
      <el-table-column label="文件名" align="center" prop="fileName" />
      <el-table-column label="文件编号" align="center" prop="taskNo" />
      <el-table-column label="文件类型" align="center" prop="fileType" />
        <!-- <template slot-scope="scope">
          <span>{{ scope.row.fileType=='1'?'文件':'文件夹' }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="上传人" align="center" prop="createBy" />
      <!-- <el-table-column label="上传科室" align="center" prop="" /> -->
      <el-table-column label="上传时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-link"
            @click="handleDownLoad(scope.row)"
          >下载</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { getFilPage } from "@/api/system/dir";
export default {
  props: {
    row: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      postList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fileName: undefined,
        taskNo: undefined,
        dateRange: undefined,
        fileType: undefined,
        createBy: undefined
      },

    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询岗位列表 */
    getList() {
      this.loading = true;
      getFilPage({...this.queryParams,id:this.row.id}).then(response => {
        this.postList = response.rows || [];
        this.total = response?.total || 0;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        postId: undefined,
        postCode: undefined,
        postName: undefined,
        postSort: 0,
        status: "0",
        remark: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 返回 */
    handleBack() {
      this.$emit("onBack");
    },
    /** 下载 */
    handleDownLoad(row){
      window.open(row.fileUrl);
    }

  }
};
</script>
